package com.bawei.mall.product.controller;

import com.bawei.common.core.utils.poi.ExcelUtil;
import com.bawei.common.core.web.controller.BaseController;
import com.bawei.common.core.web.domain.AjaxResult;
import com.bawei.common.core.web.page.TableDataInfo;
import com.bawei.common.log.annotation.Log;
import com.bawei.common.log.enums.BusinessType;
import com.bawei.common.security.annotation.RequiresPermissions;
import com.bawei.mall.product.domain.MallProductAdvertise;
import com.bawei.mall.product.service.IMallProductAdvertiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品广告Controller
 *
 * @author bawei
 * @date 2024-07-01
 */
@RestController
@RequestMapping("/Advertise")
public class MallProductAdvertiseController extends BaseController
{
    @Autowired
    private IMallProductAdvertiseService mallProductAdvertiseService;

    /**
     * 查询商品广告列表
     */
    @RequiresPermissions("product:Advertise:list")
    @GetMapping("/list")
    public TableDataInfo list(MallProductAdvertise mallProductAdvertise)
    {
        startPage();
        List<MallProductAdvertise> list = mallProductAdvertiseService.selectMallProductAdvertiseList(mallProductAdvertise);
        return getDataTable(list);
    }

    /**
     * 导出商品广告列表
     */
    @RequiresPermissions("product:Advertise:export")
    @Log(title = "商品广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallProductAdvertise mallProductAdvertise)
    {
        List<MallProductAdvertise> list = mallProductAdvertiseService.selectMallProductAdvertiseList(mallProductAdvertise);
        ExcelUtil<MallProductAdvertise> util = new ExcelUtil<MallProductAdvertise>(MallProductAdvertise.class);
        util.exportExcel(response, list, "商品广告数据");
    }

    /**
     * 获取商品广告详细信息
     */
    @RequiresPermissions("product:Advertise:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallProductAdvertiseService.selectMallProductAdvertiseById(id));
    }

    /**
     * 新增商品广告
     */
    @RequiresPermissions("product:Advertise:add")
    @Log(title = "商品广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallProductAdvertise mallProductAdvertise)
    {
        return toAjax(mallProductAdvertiseService.insertMallProductAdvertise(mallProductAdvertise));
    }

    /**
     * 修改商品广告
     */
    @RequiresPermissions("product:Advertise:edit")
    @Log(title = "商品广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallProductAdvertise mallProductAdvertise)
    {
        return toAjax(mallProductAdvertiseService.updateMallProductAdvertise(mallProductAdvertise));
    }

    /**
     * 删除商品广告
     */
    @RequiresPermissions("product:Advertise:remove")
    @Log(title = "商品广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallProductAdvertiseService.deleteMallProductAdvertiseByIds(ids));
    }
}
